package game.data;

import echo.Body;
import echo.shape.Polygon;
import echo.Shape;
import hx.geom.Rectangle;
import game.worlds.IAttackDisplay;
import game.worlds.GameRole;

/**
 * 伤害数据
 */
class HurtData {
	/**
	 * 攻击类型
	 */
	public var attackType:AttackType = NORMAL;

	/**
	 * 造成多少伤害
	 */
	public var value:Int = 0;

	/**
	 * 是否为暴击攻击
	 */
	public var isCrit:Bool = false;

	/**
	 * 受击者
	 */
	public var role:GameRole;

	/**
	 * 攻击者（可能是特效、也可能是角色）
	 */
	public var attackDisplay:IAttackDisplay;

	/**
	 * 击中事件，也可以通过`RoleEvent.EVENT`事件进行侦听
	 */
	public var event:String;

	/**
	 * 击中特效ID
	 */
	public var hitEffectId:String;

	/**
	 * 击中数据
	 */
	public var hitData:HitData;

	/**
	 * 碰撞的形状
	 */
	private var __shapes:Body;

	private var __x:Float = 0;
	private var __y:Float = 0;
	private var __scaleX:Float = 0;

	/**
	 * 获得碰撞区域矩形
	 */
	public var hitRect(get, never):Rectangle;

	private function get_hitRect():Rectangle {
		if (__shapes == null)
			return null;
		var rect = new Rectangle();
		for (shape in __shapes.shapes) {
			if (shape is Polygon) {
				var p:Polygon = cast shape;
				for (vector in p.vertices) {
					rect.expand(vector.x * __scaleX + __x, vector.y + __y, 1, 1);
				}
			}
		}
		return rect;
	}

	public function new() {}
}
